Xbasic

json_from_xml Function

Syntax

C result json = json_from_xml(xmlText as C [,topTag as C[,options as C ]])

Arguments

xmlTextCharacter

The XML to parse.

topTagCharacter

The top-level XML tag.

optionsCharacter

Optional flags that dictate how the JSON should be generated. Can be one fo the following:

Option
Description
-A

Ignore xml attributes.

Description

Produces JSON from xml. The subformat of XML is the Atom format.

Consider the following input XML:

dim xml as c = <<%str%
<qdbapi>
   <ticket>auth_ticket</ticket>
   <apptoken>app_token</apptoken>
   <query>{'11'.CT.'Bob'}AND{'19'.GTE.'5'}</query>
   <clist>6.7.9.11.16</clist>
   <slist>11.6</slist>
   <fmt>structured</fmt>
   <options>num-4.sortorder-D</options>
</qdbapi>
%str%


showvar(json_reformat(json_from_xml(xml,"qdbapi","-A")))

This produces the JSON below. Note that attributes are omitted. This is because the -A flag was passed in, indicating that attributes should be ignored.

{
    "qdbapi": {
        "ticket": "auth_ticket",
        "apptoken": "app_token",
        "query": "{'11'.CT.'Bob'}AND{'19'.GTE.'5'}",
        "clist": "6.7.9.11.16",
        "slist": "11.6",
        "fmt": "structured",
        "options": "num-4.sortorder-D"
    }
}

See Also